package com.itheima.health.controller.idem;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.result.PageResult;
import com.itheima.health.result.QueryPageBean;
import com.itheima.health.result.Result;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.CheckgroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
@Slf4j
public class CheckgroupController {
    @Autowired
    private CheckgroupService checkgroupService;

    @GetMapping("findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        log.info("[检查组项-分页查询]data:{}", queryPageBean);
        //rpc查询数据
        PageResult pageResult = checkgroupService.pageQuery(queryPageBean);
        //封装返回结果
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, pageResult);
    }
    @PostMapping("/add")
    public Result addGroup(@RequestParam("checkitemIds") List<String> checkitemIds,
                           @RequestBody CheckGroup checkGroup){
        log.info("[检查组项-添加]");
        checkgroupService.add(checkGroup,checkitemIds);
        return new Result(true, MessageConst.ADD_CHECKGROUP_SUCCESS);
    }
    @RequestMapping("/deleteCheckGroupitemById")
    public Result delete(Integer id){
        log.info("[检查组项-根据id删除]id：{}",id);
        checkgroupService.delete(id);
        return new Result(true,MessageConst.DELETE_CHECKGROUP_SUCCESS);
    }
    @PostMapping("/edit")
    public Result updateBid(@RequestBody CheckGroup checkGroup,
                            @RequestParam("checkitemIds") List<String> checkitemIds){
        log.info("[检查组项-修改]");
        checkgroupService.edit(checkGroup,checkitemIds);
        return new Result(true,MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(Integer id ){
        List<Integer> ids =  checkgroupService.findCheckItemIdsByCheckGroupId(id);
        return new Result(true,MessageConst.ACTION_SUCCESS,ids);
    }

    @RequestMapping("/findById")
    public Result findById(Integer id) {
        log.info("[检查组项-根据ID查询]id:{}", id);
        CheckGroup checkGroup = checkgroupService.findById(id);
        return new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,checkGroup);

    }
    @RequestMapping("/findAll")
    public Result findAll(){
        log.info("[套餐项-查询所有套餐组]~");
        List<CheckGroup> checkGroups = checkgroupService.findAll();
        return new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,checkGroups);

    }
}
